package star.servlet_2;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

public class hello_1 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //this.getInitParameter(); 初始化参数
        //this.getServletConfig(); servlet配置

        /**
         * web在启动的时候，他会为每个web程序创建一个ServletContext对象，代表当前web应用
         *
         *  1.在当前servlet中保存的信息可以被调用
         */
        ServletContext servletContext = this.getServletContext();

        String name = "Star_星";
        //将一个值保存在了ServletContext中，名字为”name“，值为name；
        servletContext.setAttribute("name", name );
        System.out.println("hello");

    }
}
